/*
 * @Author: your name
 * @Date: 2021-03-18 10:22:33
 * @LastEditTime: 2022-09-14 10:58:05
 * @LastEditors: 最后一次编辑说明
 * @Description: In User Settings Edit
 * @FilePath: \adminc:\Users\dell\Desktop\react (1)\新建文件夹\react\src\view\index\index.jsx
 */
import React, { Component } from 'react'
import { Toast, Carousel, WingBlank } from 'antd-mobile';
import './index.scss'
import OfferPrice from '../../components/offer/price.jsx';
import Corn from '../../components/offer/corn'
class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      bannerList: [],// banner列表
      positionType: [],// 金刚位列表
      offerTypes: [
        {
          id: 1,
          label: "豆粕",
          isShow: 0,
          path: "/offerPrice",
        },
        {
          id: 2,
          label: "玉米",
          isShow: 0,
          path: "/cornOffer",
        },
      ], // 报价类型
      cheackType: 1,// 选择的类型
    }
  }
  componentDidMount() {
    this.getBanner();
    this.getPositionType();
  }

  // 获取banner
  getBanner = () => {
    $http.get('QUERYBANNER', {
      params: {
        valid: 0
      }
    }).then(res => {
      if (res.code == 200) {
        this.setState({
          bannerList: res.ret || []
        })
      } else {
        Toast.info(ret.msg);
      }

    })
  }
  // 获取金刚位
  getPositionType = async () => {
    try {
      let res = await $http.get('QUERYBYPOSITIONTYPE', { params: { positionType: 1 } });
      // console.log(res)
      if (res.code == 200) {
        this.setState({
          positionType: res.ret || []
        })
      } else {
        Toast.fail(res.msg)
      }
    } catch (error) {
    }

  }
  // banner 点击
  toActivity(info) {
    console.log(info)
    if (info.wapLinkUrl) {
      location.href = info.wapLinkUrl;
      // window.open(info.wapLinkUrl)
    }
  }
  //金刚位点击
  vajraJump = (info) => {
    location.href = info.pageUrl;
  }
  render(h) {
    let data = this.state;
    return (
      <div id='INDEX'>
        <div className='I-banner'>
          <WingBlank>
            <Carousel className="my-carousel"
              autoplay
              infinite
            >
              {
                data.bannerList.map(item => {
                  return <div className='I-b-item flex' key={item.id} onClick={() => this.toActivity(item)}>
                    <img src={item.pictureUrl} />
                  </div>
                })
              }
            </Carousel>
          </WingBlank>
        </div>
        <div className='I-vajra flex'>
          {
            data.positionType.map(item => {
              return <div className='I-v-item flex' key={item.id} onClick={() => this.vajraJump(item)}>
                <img src={item.imgUrl} />
                <span>{item.viewName}</span>
              </div>
            })
          }
        </div>
        <div className='I-offer'>
          <div className='I-o-type flex'>
            {
              data.offerTypes.map(item => {
                return <span className={`I-type-item ${data.cheackType == item.id ? 'I-type-active' : ''}`} key={item.id} onClick={() => {
                  this.setState({
                    cheackType: item.id
                  })
                }}>{item.label}</span>
              })
            }

          </div>
          <div className='I-offer-content'>
            {
              data.cheackType == 1 ? <OfferPrice history={ this.props.history}></OfferPrice> : <Corn></Corn>
            }


          </div>
        </div>
      </div>

    )
  }
}
export default Index